<?php
	//引入配置文件和数据库操作函数
	require '../../public/config.php';
	require '../../public/mysql.php';
	  session_start();



	//接受传递过来的用户查询数据
    $search = empty($_GET['username'])?'':$_GET['username'];

    if(!empty($search)){
		$where = "and username like '%{$search}%'";
	}else{
		$where='';
	}
	$where1='';
	//echo $_GET['search_sex'];
	if(isset($_GET['search_sex'])&&$_GET['search_sex'] !=''){
		$where1 = "and sex='{$_GET['search_sex']}' ";
	}
    $where2='';
	if(isset($_GET['search_role'])&&$_GET['search_role'] !=''){
		$where2 = "and role='{$_GET['search_role']}' ";
	}


	$page=empty($_GET['p'])?1:$_GET['p'];
	//连接数据库
	$link = connect();
    //var_dump($link);
	
    $sql="select count(*) as total from vip where 1 $where $where1 $where2 ";
	$result=query($link['mess'],$sql);
	$total = $result[0]['total'];
    //var_dump($totals);
	$num=6;
	$totalPage=ceil($total / $num);
	//var_dump($totalPage);
	//判断页面是否小0
	if ($page < 0) {
		$page = 1;
	}

	//判断页面是大于最大的页面
	if ($page > $totalPage) {
		$page = $totalPage;
	}
	$start = ($page - 1) * $num;
	$sql = "select * from vip  where 1 $where $where1 $where2 limit $start,$num ";
	//echo '<pre>';
	//print_r($sql);
	
	$res=mysqli_query($link['mess'],$sql);
	if($res){
		while($row=mysqli_fetch_assoc($res)){
			$rows[]=$row;
		}
	}
	$result=@$rows;
	//var_dump($result);
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ECSHOP 管理中心 - 商品列表 </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../include/Css/general.css" rel="stylesheet" type="text/css" />
<link href="../include/Css/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>
   
    <span class="action-span1"><a href="__GROUP__">用户管理中心</a></span>
    <span id="search_id" class="action-span1"> - 用户列表 </span>
    <div style="clear:both"></div>
</h1>
<div class="form-div">
    <form action="./addList.php" name="searchForm" method='get'>
        <img src="../include/Images/icon_search.gif" width="26" height="22" border="0" alt="search" />
 
        <!-- 关键字 -->
		
        关键字:<input type="text" name="username" size="15" />
        性别:<input type="radio" name="search_sex" value="0"  />男
        <input type="radio" name="search_sex" value="1" />女
		
        <input type="submit" value=" 搜索 " class="button" />
    </form>
</div>

<!-- 商品列表 -->
<form method="post" action="" name="listForm" onsubmit="">
    <div class="list-div" id="listDiv">
        <table cellpadding="3" cellspacing="1">
            <tr>
                <th>id</th>
                <th>用户名</th>
                <th>性别</th>
                <th>电话</th>
                <th>邮箱</th>
                
                <th>添加时间</th>
                <th>操作</th>

            </tr>
			<?php if (!empty($rows)) :?>
			<?php $i=1;?>
				 <?php				
				 //性别标识
				$sex = array(0=>'男', 1=>'女');
		
			?>
			<?php foreach ($rows as $val) :?>
            <tr>
                <td align="center"><?php echo $i;?></td>
                <td align="center" class="first-cell"><span><?php echo $val['username'];?></span></td>
                <td align="center"><span onclick=""><?php echo $sex[$val['sex']];?></span></td>
                <td align="center"><span><?php echo $val['phone'];?></span></td>
                <td align="center"><?php echo $val['email'];?></td>
                
                <td align="center"><span><?php echo date('Y-m-d H:i:s', $val['addtime'])?></span></td>
                <td align="center">
                
                <a href="./action.php?a=deladd&id=<?php echo $val['id']?>" onclick="" title="回收站"><img src="../include/Images/icon_trash.gif" width="16" height="16" border="0" /></a></td>
            </tr>
			<?php $i++;?>
			<?php endforeach;?>
			<?php else:?>
			<tr>
				<td colspan="9">暂无信息</td>
			</tr>
			<?php endif;?>
        </table>

    <!-- 分页开始 -->
        <table id="page-table" cellspacing="0">
            <tr>
                <td width="80%">&nbsp;</td>
                <td align="center" nowrap="true">
				   <span>共<?php echo $totalPage?>页</span>
				   <span>第<?php echo $page?>/<?php echo $totalPage?>页</span>
                    <a href="addList.php?p=1">首页</a>
					<a href="addList.php?p=<?php echo $page - 1?>">上一页</a>
					<a href="addList.php?p=<?php echo $page + 1?>">下一页</a>
					<a href="addList.php?p=<?php echo $totalPage?>">尾页</a>
                </td>
            </tr>
        </table>
    <!-- 分页结束 -->
    </div>
</form>

<div id="footer">
共执行 7 个查询，用时 0.028849 秒，Gzip 已禁用，内存占用 3.219 MB<br />
版权所有 &copy; 2005-2012 暴走少年哈尔，并保留所有权利。</div>
</body>
</html>